<?php
class ss_doctrine_query extends Doctrine_Query
{
	static protected $HYDRATORS=array(Doctrine::HYDRATE_ARRAY,'jsonRef',Doctrine::HYDRATE_RECORD);
	static public $LIMIT=10;
	
	public function getAll($params=array(),$hydrator=null,$limit=null){
		//ss_error::log($hydrator,'Hydrator');
		//if(is_null($limit)) $limit=self::$LIMIT;
		if(is_null($hydrator)) $hydrator=self::$HYDRATORS[ss_doctrine_table::$RELATION_MODE];
		$this->setLimit($limit);
		return $this->execute($params,$hydrator);
	}
	
	public function getOne($params=array(),$hydrator=null){
		if(is_null($hydrator)) $hydrator=self::$HYDRATORS[ss_doctrine_table::$RELATION_MODE];
		return $this->fetchOne($params,$hydrator);
	}
	
	public function getCount($params=array()){
		$_temp=$this->_dqlParts['limit'];
		$this->_dqlParts['limit']=array();
		$_count=$this->count($params);
		//ss_error::log($_count,'Count');
		//ss_error::log($this->getCountSqlQuery(),'Count SQL query');
		$this->_dqlParts['limit']=$_temp;
		return $_count;
	}
	
	protected function setLimit($limit){
		if(is_null($limit) && count($this->getDqlPart('limit'))==0) $limit=self::$LIMIT;
		if(is_array($limit)){
			$this->offset((int)$limit[0]);
			$this->limit((int)$limit[1]);
		} elseif(is_numeric($limit) && $limit>0){
			$this->limit($limit);
		}
		//ss_error::info($this,'Query with limit');
	}
}
?>